# Contributor: kpcyrd <git@rxv.cc>
# Maintainer: kpcyrd <git@rxv.cc>
pkgname=cargo-edit
pkgver=0.12.2
pkgrel=0
pkgdesc="Managing cargo dependencies from the command line"
url="https://github.com/killercup/cargo-edit"
# s390x, ppc64le, riscv64: blocked by ring crate
arch="all !s390x !ppc64le !riscv64"
license="MIT OR Apache-2.0"
makedepends="
	cargo
	cargo-auditable
	libgit2-dev
	libssh2-dev
	openssl-dev>3
	"
subpackages="$pkgname-doc"
options="net"
source="$pkgname-$pkgver.tar.gz::https://github.com/killercup/cargo-edit/archive/v$pkgver.tar.gz"

export LIBSSH2_SYS_USE_PKG_CONFIG=1  # use system libssh2

# Exclude vendored-libgit2 feature.
_cargo_opts="--frozen --no-default-features --features add,rm,upgrade,set-version"

prepare() {
	default_prepare

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided libs
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		git2 = { rustc-link-lib = ["git2"] }
	EOF

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build $_cargo_opts --release
}

check() {
	cargo test $_cargo_opts
}

package() {
	install -Dm644 -t "$pkgdir/usr/share/doc/cargo-edit" README.md
	cd target/release
	install -Dm755 cargo-rm cargo-add cargo-set-version cargo-upgrade \
		-t "$pkgdir"/usr/bin/
}

sha512sums="
91750b1129eebbbc86d9eb1e3e3ed428039b4997975a7708acee60cd537b5daa4a1de0ed64462162fa82b73a15795c1e1603aaac2f7bcc1570ec83c147f0c207  cargo-edit-0.12.2.tar.gz
"
